<template>
  <div :ref="refName" :style="{ height: height, width: width }" />
</template>

<script>
import resize from "@/mixins/chartResize";
export default {
  name: "VsChart",
  mixins: [resize],
  props: {
    // 样式
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
    refName: {
      type: String,
      default: "chart",
    },
    title:{
      type:Object,
    },
    tooltip:{
      type:Object,
      default:()=>{
        return{
        trigger: 'axis',
        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        }
      }
    },
    grid:{
      type:Object,
      default:()=>{
        return{
          left: '2%',
          right: '2%',
          bottom: '2%',
          top:'2%',
          containLabel: true
        }
      }
    },
    xAxis:{
      type:Object,
      default:()=>{
        return{
          type: 'category'
        }      
      }
    },
    yAxis:{
      type:Object,
      default:()=>{
        return{
          type: 'value'
        }      
      }
    },
    series:Array
  },
  data() {
    return {
      chart: null,
    };
  },
  watch: {
    $props: {
      handler(newVal) {
        this.drawChart();
      },
      deep: true,
    },
  },
  mounted() {
    this.$nextTick(()=>{
      this.drawChart();
    })
  },
  methods: {
   drawChart() {
      this.chart = this.$echarts.init(this.$refs[this.refName], "macarons");
      this.chart.setOption({
        title:this.title,
        tooltip: this.tooltip,
        grid:this.grid,
        legend: this.legend,
        xAxis: this.xAxis,
        yAxis:this.yAxis,
        series:this.series
      });
    },
  },
};
</script>

<style lang="less" scoped>
</style>
